package guda.mrpc.core.server;

import guda.mrpc.core.RequestKey;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by well on 17/6/3.
 */
public class DefaultServiceProviderContainer implements ServiceProviderContainer{


    private ConcurrentHashMap<String, Object> serviceMap = new ConcurrentHashMap();

    @Override
    public void registerService(String serviceKey, Object serviceObject) {
        serviceMap.put(serviceKey,serviceObject);
    }

    @Override
    public Object lookupService(String serviceKey) {
        return serviceMap.get(serviceKey);
    }

    @Override
    public Object removeService(String serviceKey) {
        return serviceMap.remove(serviceKey);
    }

    @Override
    public List<String> getAllServices() {
        if(serviceMap.size() ==0){
            return Collections.emptyList();
        }
        return new ArrayList(serviceMap.keySet());

    }
}
